<?php

function json_success($contents = [],$message = 'success'){
    return json_response(0,$message,$contents);
}

function json_error($errcode,$message = 'failed',$contents = []){
    return json_response($errcode,$message,$contents);
}

function json_response($errcode,$message,$contents){
    $json = ['errcode'=>$errcode,'message'=>$message];
    if(!empty($contents)){
        $json['contents'] = $contents;
    }
    return $json;
}

function array_null_to_empty($array){
    array_walk_recursive($array,function(&$val,$key){
        if($val == null){
            $val = '';
        }
    });
    return $array;
}
